#include <iostream>
using namespace std;

struct ListNode {
    int val;
    ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};


ListNode *deleteDuplicates(ListNode *head) {
    // Start typing your C/C++ solution below
    // DO NOT write int main() function
    if(!head)
        return NULL;
    ListNode *pRead = head->next;
    ListNode *pWrite = head;
    while(pRead){
        if(pRead->val != pWrite->val){
            pWrite->next = pRead;
            pWrite = pWrite->next;
        }
        pRead = pRead->next;
    }
    pWrite->next = NULL;
    return head;
}